import 'package:seedfour/generated/json/base/json_convert_content.dart';
import 'package:seedfour/app/models/payees_entity.dart';

PayeesEntity $PayeesEntityFromJson(Map<String, dynamic> json) {
  final PayeesEntity payeesEntity = PayeesEntity();
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    payeesEntity.name = name;
  }
  final List<PayeesItems>? items = (json['items'] as List<dynamic>?)?.map(
          (e) => jsonConvert.convert<PayeesItems>(e) as PayeesItems).toList();
  if (items != null) {
    payeesEntity.items = items;
  }
  return payeesEntity;
}

Map<String, dynamic> $PayeesEntityToJson(PayeesEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['name'] = entity.name;
  data['items'] = entity.items?.map((v) => v.toJson()).toList();
  return data;
}

extension PayeesEntityExtension on PayeesEntity {
  PayeesEntity copyWith({
    String? name,
    List<PayeesItems>? items,
  }) {
    return PayeesEntity()
      ..name = name ?? this.name
      ..items = items ?? this.items;
  }
}

PayeesItems $PayeesItemsFromJson(Map<String, dynamic> json) {
  final PayeesItems payeesItems = PayeesItems();
  final String? uid = jsonConvert.convert<String>(json['uid']);
  if (uid != null) {
    payeesItems.uid = uid;
  }
  final String? name = jsonConvert.convert<String>(json['name']);
  if (name != null) {
    payeesItems.name = name;
  }
  final bool? grouped = jsonConvert.convert<bool>(json['grouped']);
  if (grouped != null) {
    payeesItems.grouped = grouped;
  }
  final List<PayeesItemsOptions>? options = (json['options'] as List<dynamic>?)
      ?.map(
          (e) =>
      jsonConvert.convert<PayeesItemsOptions>(e) as PayeesItemsOptions)
      .toList();
  if (options != null) {
    payeesItems.options = options;
  }
  final bool? zeroSettle = jsonConvert.convert<bool>(json['zeroSettle']);
  if (zeroSettle != null) {
    payeesItems.zeroSettle = zeroSettle;
  }
  return payeesItems;
}

Map<String, dynamic> $PayeesItemsToJson(PayeesItems entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['uid'] = entity.uid;
  data['name'] = entity.name;
  data['grouped'] = entity.grouped;
  data['options'] = entity.options.map((v) => v.toJson()).toList();
  data['zeroSettle'] = entity.zeroSettle;
  return data;
}

extension PayeesItemsExtension on PayeesItems {
  PayeesItems copyWith({
    String? uid,
    String? name,
    bool? grouped,
    List<PayeesItemsOptions>? options,
    bool? zeroSettle,
  }) {
    return PayeesItems()
      ..uid = uid ?? this.uid
      ..name = name ?? this.name
      ..grouped = grouped ?? this.grouped
      ..options = options ?? this.options
      ..zeroSettle = zeroSettle ?? this.zeroSettle;
  }
}

PayeesItemsOptions $PayeesItemsOptionsFromJson(Map<String, dynamic> json) {
  final PayeesItemsOptions payeesItemsOptions = PayeesItemsOptions();
  final String? settleMethod = jsonConvert.convert<String>(
      json['settleMethod']);
  if (settleMethod != null) {
    payeesItemsOptions.settleMethod = settleMethod;
  }
  final int? settleRatio = jsonConvert.convert<int>(json['settleRatio']);
  if (settleRatio != null) {
    payeesItemsOptions.settleRatio = settleRatio;
  }
  final String? desc = jsonConvert.convert<String>(json['desc']);
  if (desc != null) {
    payeesItemsOptions.desc = desc;
  }
  return payeesItemsOptions;
}

Map<String, dynamic> $PayeesItemsOptionsToJson(PayeesItemsOptions entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['settleMethod'] = entity.settleMethod;
  data['settleRatio'] = entity.settleRatio;
  data['desc'] = entity.desc;
  return data;
}

extension PayeesItemsOptionsExtension on PayeesItemsOptions {
  PayeesItemsOptions copyWith({
    String? settleMethod,
    int? settleRatio,
    String? desc,
  }) {
    return PayeesItemsOptions()
      ..settleMethod = settleMethod ?? this.settleMethod
      ..settleRatio = settleRatio ?? this.settleRatio
      ..desc = desc ?? this.desc;
  }
}